package com.ms.p2p.service.impl;


import com.ms.p2p.bean.PageBean;
import com.ms.p2p.dao.AuthDao;
import com.ms.p2p.dao.MemberAccountBankDao;
import com.ms.p2p.dao.MemberAccountDao;
import com.ms.p2p.entity.account.Account;
import com.ms.p2p.entity.account.AccountBank;
import com.ms.p2p.entity.member.Auth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

/**
 * 银行卡
 */
@Service
public class MemberAccountBankServiceImpl {

	@Autowired
	private MemberAccountBankDao memberAccountBankDao;

	@Autowired
	private MemberAccountDao memberAccountDao;


	@Autowired
	private AuthDao authDao;

	/**
	 *
	 * 用用户名查找银行卡
	 *
	 * @param userId
	 * @return
	 */
	public AccountBank findByUserId(int userId) {
		return memberAccountBankDao.findByUserId(userId);

	}

	/**
	 * 新增银行卡
	 * @return
	 */
	public int insert(AccountBank bank) {
		return memberAccountBankDao.insert(bank);

	}

	/**
	 * 根据用户ID修改银行卡
	 *
	 * @param bank
	 * @return
	 */
	public int updateByUserId(AccountBank bank) {
		return memberAccountBankDao.updateByUserId(bank);

	}

	public List<Map<String, Object>> findPager(String userId, String userName,
			PageBean page) {

		return memberAccountBankDao.findPager(page.getBegin(), page.getPageSize(),
				userId, userName);
	}


	public List<Map<String, Object>> findAll(String userId, String userName) {

		return memberAccountBankDao.findAll(userId, userName);
	}

	public int findCount(String userId, String userName) {
		return memberAccountBankDao.findCount(userId, userName);
		// return dao.queryForInt(TablePrefixFormat.format(sql));
	}
//
//	public List<Dict> selectdictList() {
//		HashMap map = new HashMap();
//		map.put("type_id", 25);
//		List<Dict> list = dictDao.findAllList(map);
//		return list;
//	}

	public Auth selectRealByUserId(int user_id) {

		return authDao.findByUserId(user_id);

	}

	public AccountBank selectMrAccountBankByUserId(int user_id) {

		return memberAccountBankDao.findByUserId(user_id);

	}

	public Account selectAccountByUserId(int user_id) {
		return memberAccountDao.findByUserId(user_id);

	}

	public AccountBank selectAccountBankByUserId(int user_id) {
		return memberAccountBankDao.findByUserId(user_id);

	}

	public AccountBank selectAccountBankById(String id) {
		return (AccountBank) memberAccountBankDao.get(id);

	}

	public int inserted(AccountBank bank, String paypassword, int id, String bankId)
	{

		int i = 0;
		String sql = null;
		if (!"".equals(bankId)) {

			sql = "";
			i = memberAccountBankDao.update(bank);
		} else {
			i = memberAccountBankDao.insert(bank);
		}

		return i;
	}

	public void delete(Integer id) {
		memberAccountBankDao.deleteById(id);
	}
}
